package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.AuthLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.dto.UpdateUserDto;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.GetUserInfoVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "微信授权登录接口")
@RestController
@RequestMapping("/api/user/wxLogin")
@Slf4j
public class WxLoginApiController {

    @Autowired
    private UserInfoService userInfoService;
//     /api/user/wxLogin/wxLogin/{code}

    @GetMapping("wxLogin/{code}")
    public Result<Map<String,String>> wxLogin(@PathVariable String code){
        HashMap<String, String> map = new HashMap<>();
        map.put("token",userInfoService.wxLogin(code));
        return Result.ok(map);
    }

//     /api/user/wxLogin/getUserInfo
    @AuthLogin
    @GetMapping("getUserInfo")
    public Result<GetUserInfoVo> getUserInfo(){
        return Result.ok(userInfoService.getUserInfo());
    }
//     UpdateUserDto
//     /api/user/wxLogin/updateUser
    @AuthLogin
    @PostMapping("updateUser")
    public Result<Object> updateUser(@RequestBody UpdateUserDto updateUserDto){
        userInfoService.updateUser(updateUserDto);
        return Result.ok();
    }



}
